package com.example.javadocsearcher.controller;

/**
 * Created with IntelliJ IDEA 2023.
 * Description:
 * User: homechen
 * Date: 2024-03-06
 * Time: 20:30
 */

import com.example.javadocsearcher.common.DocSearcher;
import com.example.javadocsearcher.entity.AjaxResult;
import com.example.javadocsearcher.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户搜索内容的入口
 */
@RestController
@RequestMapping("/searcher")
public class DocSearcherController {
    @Autowired
    private DocSearcher docSearcher;

    @RequestMapping("/getlist")
    public AjaxResult searcher(@RequestParam("query") String query) {
        // 判断参数是否正确
        if (query == null) {
            return AjaxResult.fail(-1, "非法参数");
        }
        List<Result> resultList = docSearcher.searcher(query);
        return AjaxResult.success(resultList);
    }
}
